#include "mainwindow.h"
#include "QPushButton"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    this->setWindowTitle("信号和槽");
    this->resize(600, 400);

    //系统自带信号和槽
    //关闭窗口
    //QPushButton *closeBtn = new QPushButton("关闭窗口", this);
    //closeBtn : 发出信号的对象
    //&QPushButton::clicked: 发出的信号
    //this: 接受信号的对象
    //&MainWindow::close: 接收对象在接收到信号之后所需要调用的函数(槽函数)
    //connect(closeBtn, &QPushButton::clicked, this, &MainWindow::close);


    this->t = new Teacher(this);
    this->s = new Student(this);
    //连接信号和槽
    connect(t, &Teacher::hungry, s, &Student::treat);

    classIsOver();

}

//触发
void MainWindow::classIsOver(){
    emit this->t->hungry();
}


MainWindow::~MainWindow()
{
}

